1. /* sdflogag.cpp by K.Tsuru */
  2. // function ID 3405 DARDIX. Remade ver. 2.30
  3. /****************************************************
  4. log(x) by AGM (Arithmetic-Geometric Mean) method for x > 0
  5. It needs the constant Pi().
  6. [Reference]
  7. "Arugorizum Jiten(Algorithm Dictionary, in Japanese)"
  8. Kyoritsu Syuppan, 1994, p.363
  9. *****************************************************/
  10. #ifndef SN_H
  11. #include "sn.h"
  12. #endif
  13. static void Kt3(const SDouble& q, SDouble& K, SDouble& t3){
  14. SDouble t0(q), qnn(q), q2(q*q), q2n1(q2*q);
  15. t3 = q;
  16. int i = 0;
  17. while(1){
  18. qnn *= q2n1;
  19. if(i & 1) t0 += qnn;
  20. else t0 -= qnn;
  21. t3 += qnn;
  22. if(qnn.IsMLT(ONE)) break;
  23. q2n1 *= q2;
  24. i++;
  25. }
  26. t0 = ONE - 2*t0; t3 = ONE + 2*t3;
  27. q2 = t0/t3; q2 *= q2; q2*=q2;
  28. t0 = ONE - q2; K = Sqrt(t0);
  29. }
  30. /***********
  31. x must be 0 < x < O(1)
  32. ************/
  33. static SDouble SNLogAGM(const SDouble& x){
  34. RealSize C;
  35. SDouble a(1.0), b, q, d, t3, K, r;
  36. Kt3(x, b, t3); //It evaluates 'b' and 't3' from 'x'.
  37. while(1){
  38. q = (a+b)/2.0;
  39. b = Sqrt(a*b);
  40. a = q;
  41. d = a-b;
  42. if(d.IsMLT(a)) break;
  43. }
  44. a = (a+b)/2.0;
  45. d = t3*t3;
  46. r = Pi()/(a*d);
  47. r.ChangeSign();
  48. return r;
  49. }
  50. /***********
  51. main body
  52. ***********/
  53. SDouble LogAGM(const SDouble& x){
  54. SDouble X, add;
  55. // x = X*10^exp. log(x) = log(X)+exp*log(10), add = exp*log(10), 0< X < 1
  56. if( GetLogxCalcMethod(x, X, add) ) return X; // x= 1 or 10, X=0 or log(10)
  57. return ( SNLogAGM(X) + add );
  58. }

sdflogag.cpp : last modifiled at 2016/08/29 16:50:48(1,463 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).